package com.wteam.dragon.model.controller;

import com.wteam.dragon.model.service.impl.FileServiceImpl;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.apps.security.annotation.AnonymousAccess;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.util.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author 陈晓辉
 * @Date 2020/4/10 11:56
 */
@RestController
@Api(tags = "源：文件上传")
@RequestMapping("file")
@RequiredArgsConstructor
public class FileController {
    private final FileServiceImpl fileServiceImpl;

    @Log("上传图片文件")
    @ApiOperation("上传图片文件")
    @PostMapping("uploadPictureFile")
    @AnonymousAccess
    public ResultMessage uploadPictureFile(MultipartFile file, String typePath){
        return fileServiceImpl.uploadFile(file, typePath, FileUtil.FileType.PICTURE);
    }

    @Log("上传视频文件")
    @ApiOperation("上传视频文件")
    @PostMapping("uploadVideoFile")
    @AnonymousAccess
    public ResultMessage uploadVideoFile(MultipartFile file, String typePath){
        return fileServiceImpl.uploadFile(file, typePath, FileUtil.FileType.VIDEO);
    }

    @Log("上传音乐文件")
    @ApiOperation("上传音乐文件")
    @PostMapping("uploadAudioFile")
    @AnonymousAccess
    public ResultMessage uploadAudioFile(MultipartFile file, String typePath){
        return fileServiceImpl.uploadFile(file, typePath, FileUtil.FileType.MUSIC);
    }

    @Log("上传文档文件")
    @ApiOperation("上传文档文件")
    @PostMapping("uploadDocumentsFile")
    @AnonymousAccess
    public ResultMessage uploadDocumentsFile(MultipartFile file, String typePath){
        return fileServiceImpl.uploadFile(file, typePath, FileUtil.FileType.DOCUMENTS);
    }
}
